package reply

/**
常量的正常回复
*/

// PongReply 回复 ping
type PongReply struct{}

var pongBytes = []byte("+PONG\r\n")

func (r *PongReply) ToBytes() []byte {
	return pongBytes
}

var thePingReply = new(PongReply)

func MakePingReply() *PongReply {
	return thePingReply
}

// OkReply 回复 ok
type OkReply struct{}

var okBytes = []byte("+OK\r\n")

func (r *OkReply) ToBytes() []byte {
	return okBytes
}

// 在外部定义，不需要每次调用 MakeOkReply 时都动态新建，节约内存
var theOkReply = new(OkReply)

// MakeOkReply return a ok reply
func MakeOkReply() *OkReply {
	return theOkReply
}

// NullBulkReply null 回复
type NullBulkReply struct {
}

var nullBulkReply = []byte("$-1\r\n")

func (r *NullBulkReply) ToBytes() []byte {
	return nullBulkReply
}

func MakeNullBulkReply() *NullBulkReply {
	return &NullBulkReply{}
}

// EmptyMultiBulkReply 回复空数组
type EmptyMultiBulkReply struct{}

var emptyMultiBulkBytes = []byte("*0\r\n")

// ToBytes marshal redis.Reply
func (r *EmptyMultiBulkReply) ToBytes() []byte {
	return emptyMultiBulkBytes
}

// MakeEmptyMultiBulkReply creates EmptyMultiBulkReply
func MakeEmptyMultiBulkReply() *EmptyMultiBulkReply {
	return &EmptyMultiBulkReply{}
}

// NoReply respond nothing, for commands like subscribe
type NoReply struct{}

var noBytes = []byte("")

func (r *NoReply) ToBytes() []byte {
	return noBytes
}
